package com.elm.controller;

import com.elm.po.Cart;
import com.elm.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @PostMapping("/saveCart")
    public int saveCart(@RequestBody Cart cart) {
        return cartService.saveCart(cart);
    }

    @PutMapping("/updateCart")
    public int updateCart(@RequestBody Cart cart) {
        return cartService.updateCart(cart);
    }

    @DeleteMapping("/removeCart")
    public int removeCart(@RequestBody Cart cart) {
        return cartService.removeCart(cart);
    }

    @GetMapping("/getCart")
    public List<Cart> getCart(@RequestParam(required = false) Integer businessId) {
        Cart cart = new Cart();
        cart.setBusinessId(businessId);
        return cartService.getCart(cart);
    }
}